home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swags_z.zip / TEXTFILE.SWG / 0003_LINE-CNT.PAS.pas < prev    next >
Pascal/Delphi Source File  |  1993-05-28  |  2KB  |  90 lines

  1. {
  2. >I'm wondering if anyone can post me a source For another way to
  3. >find out the max lines in a Text File.
  4. }
  5.  
  6.  {.$DEFinE DebugMode}
  7.  
  8.  {$ifDEF DebugMode}
  9.  
  10.    {$A+,B-,D+,E-,F-,G+,I+,L+,N-,O-,P-,Q+,R+,S+,T+,V+,X-}
  11.  
  12.  {$else}
  13.  
  14.    {$A+,B-,D-,E-,F-,G+,I-,L-,N-,O-,P-,Q-,R-,S-,T-,V-,X-}
  15.  
  16.  {$endif}
  17.  
  18.  {$M 1024,0,0}
  19.  
  20. Program LineCounter;
  21.  
  22. Const
  23.   co_LineFeed = 10;
  24.  
  25. Type
  26.   byar_60K = Array[1..61440] of Byte;
  27.  
  28. Var
  29.   wo_Index,
  30.   wo_BytesRead : Word;
  31.  
  32.   lo_FileSize,
  33.   lo_BytesProc,
  34.   lo_LineCount : LongInt;
  35.  
  36.   fi_Temp      : File;
  37.  
  38.   byar_Buffer  : byar_60K;
  39.  
  40. begin
  41.               (* Attempt to open TEST.doC File.                       *)
  42.   assign(fi_Temp, 'linecnt.pas');
  43.   {$I-}
  44.   reset(fi_Temp, 1);
  45.   {$I+}
  46.  
  47.               (* Check if attempt was sucessful.                      *)
  48.   if (ioresult <> 0) then
  49.     begin
  50.       Writeln('ERRor opening TEST.doC File');
  51.       halt
  52.     end;
  53.  
  54.               (* Record the size in Bytes of TEST.doC .               *)
  55.   lo_FileSize := Filesize(fi_Temp);
  56.  
  57.               (* Initialize Variables.                                *)
  58.   lo_LineCount := 0;
  59.   lo_BytesProc := 0;
  60.  
  61.               (* Repeat Until entire File has been processed.         *)
  62.   Repeat
  63.               (* Read in all or a 60K chunk of TEST.doC into the      *)
  64.               (* "buffer" For processing.                             *)
  65.     blockread(fi_Temp, byar_Buffer, sizeof(byar_60K), wo_BytesRead);
  66.  
  67.               (* Count the number of line-feed Characters in the      *)
  68.               (* "buffer".                                            *)
  69.     For wo_Index := 1 to wo_BytesRead do
  70.       if (byar_Buffer[wo_Index] = co_LineFeed) then
  71.         inc(lo_LineCount);
  72.  
  73.               (* Record the number of line-feeds found in the buffer. *)
  74.     inc(lo_BytesProc, wo_BytesRead)
  75.  
  76.   Until (lo_BytesProc = lo_FileSize);
  77.  
  78.               (* Close the TEST.doC File.                             *)
  79.   close(fi_Temp);
  80.  
  81.               (* Display the results.                                 *)
  82.   Writeln(' total number of lines in LinECNT.PAS = ', lo_LineCount)
  83.  
  84. end.
  85. {
  86.   ...to find a specific line, you'll have to process the Text File up
  87.   to the line you are after, then use a "seek" so that you can read
  88.   in just this line into a String Variable. (You'll have to determine
  89.   the length of the String, and then set the String's length-Byte.)
  90. }